package com.wcgksoft.controller.admin;

import com.wcgksoft.common.util.Layui;
import com.wcgksoft.entity.admin.Account;
import com.wcgksoft.service.admin.AccountService;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author 御风
 * @version V1.0
 * @Package com.wcgksoft.controller.admin
 * @Description TODO
 * @date 2020/5/22 16:27
 * @ClassName AccountValidateController
 */
@Controller
@RequestMapping("account")
public class AccountValidateController {
    @Autowired
    private AccountService accountService;

    @ResponseBody
    @RequestMapping(value = "validateUserName")
    public Layui validateUserName(@RequestParam(value = "userName",required = false)String userName){
        DetachedCriteria criteria = DetachedCriteria.forClass(Account.class);
        if (StringUtils.isNotEmpty(userName)){
            criteria.add(Restrictions.eq("userName",userName));
        }
        List<Account> list = accountService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validatePhone")
    public Layui validatePhone(@RequestParam(value = "phone",required = false)String phone){
        DetachedCriteria criteria = DetachedCriteria.forClass(Account.class);
        if (StringUtils.isNotEmpty(phone)){
            criteria.add(Restrictions.eq("phone",phone));
        }
        List<Account> list = accountService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validateBankNum")
    public Layui validateBankNum(@RequestParam(value = "bankNum",required = false)String bankNum){
        DetachedCriteria criteria = DetachedCriteria.forClass(Account.class);
        if (StringUtils.isNotEmpty(bankNum)){
            criteria.add(Restrictions.eq("bankNum",bankNum));
        }
        List<Account> list = accountService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }

    @ResponseBody
    @RequestMapping(value = "validateIdCard")
    public Layui validateIdCard(@RequestParam(value = "idCard",required = false)String idCard){
        DetachedCriteria criteria = DetachedCriteria.forClass(Account.class);
        if (StringUtils.isNotEmpty(idCard)){
            criteria.add(Restrictions.eq("idCard",idCard));
        }
        List<Account> list = accountService.findByConditions(criteria);
        return Layui.data(0, "success",  list);
    }


}
